home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr2.arc / MEMCMP.C < prev    next >
Text File  |  1987-03-04  |  1KB  |  34 lines

  1. /*  File   : memcmp.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 25 May 1984
  4.     Defines: memcmp()
  5.  
  6.     memcmp(lhs, rhs, len)
  7.     compares the two memory areas lhs[0..len-1]  ??  rhs[0..len-1].   It
  8.     returns  an integer less than, equal to, or greater than 0 according
  9.     as lhs[-] is lexicographically less than, equal to, or greater  than
  10.     rhs[-].  Note  that this is not at all the same as bcmp, which tells
  11.     you *where* the difference is but not what.
  12.  
  13.     Note:  suppose we have int x, y;  then memcmp(&x, &y, sizeof x) need
  14.     not bear any relation to x-y.  This is because byte order is machine
  15.     dependent, and also, some machines have integer representations that
  16.     are shorter than a machine word and two equal  integers  might  have
  17.     different  values  in the spare bits.  On a ones complement machine,
  18.     -0 == 0, but the bit patterns are different.
  19.  
  20.     This could have a Vax assembly code version, but as the return value
  21.     is not the value left behind by  the  cmpc3  instruction  I  haven't
  22.     bothered.
  23. */
  24.  
  25. int memcmp(lhs, rhs, len)
  26.     register char *lhs, *rhs;
  27.     register int len;
  28.     {
  29.        while (--len >= 0)
  30.            if (*lhs++ != *rhs++) return lhs[-1]-rhs[-1];
  31.        return 0;
  32.     }
  33.  
  34.